package com.armani.service.impl;

import com.armani.entity.User;
import com.armani.mapper.UserMapper;
import com.armani.model.UserModel;
import com.armani.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName: armani
 * @Package: com.armani.service.Impl
 * @ClassName: UserServiceImpl
 * @Description: TODO
 * @Author: Roc
 * @Date: 2021/11/27 18:39
 * @Version: 1.0
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> ListSearch(Integer level, String user,
                                 Integer startRow, Integer limit) {
        return userMapper.ListSearch(level, user, startRow, limit);
    }

    @Override
    public Integer getCount(Integer level, String user) {
        return userMapper.getCount(level, user);
    }

    @Override
    @Transactional
    public Integer insert(String userName, String user, String password, String phone,
                          String sex, String cardId, Date birth, String email, Date createtime,
                          Integer level, BigDecimal balance, Integer zhuangtai) {
        return userMapper.insert(userName, user, password, phone, sex, cardId, birth,
                email, createtime, level, balance, zhuangtai);
    }

    @Override
    @Transactional
    public Integer update(String userName, String user, String password,
                          String phone, String sex, String cardId, Date birth,
                          String email, Date createtime, Integer level, BigDecimal balance, Integer zhuangtai, Integer id) {
        return userMapper.update(userName, user, password, phone, sex, cardId, birth,
                email, createtime, level, balance, zhuangtai, id);
    }

    @Override
    @Transactional
    public Integer delete(Integer id) {
        return userMapper.delete(id);
    }

    @Override
    public Integer ztupdate(String zhuangtai, Integer id) {
        return userMapper.ztupdate(zhuangtai, id);
    }

    /**
     * 用户登录
     *
     * @param userModel 参数（用户名、密码）
     * @return 当前用户信息
     */
    @Override
    public User login(UserModel userModel) {
        userModel.setCreateTime(new Date());
        User user = userMapper.login(userModel);
        return user;
    }

    /**
     * 注册
     *
     * @param userModel 参数（用户名、密码、生日等）
     * @return 影响行
     */
    @Override
    public Integer register(UserModel userModel) {
        userModel.setCreateTime(new Date());
        Integer row =userMapper.register(userModel);
        return row;
    }
}
